/**
* 左边菜单
*/ 
<template>
  <el-menu default-active="2" :collapse="collapsed" collapse-transition router :default-active="$route.path" unique-opened class="el-menu-vertical-demo" background-color="#334157" text-color="#fff" active-text-color="#ffd04b">
    <div class="logobox">
      <img class="logoimg"  v-bind:src="avatar" alt="">
    </div>
    
    <el-submenu v-for="menu in allmenu" :key="menu.menuid" :index="menu.label">
      <template slot="title">
        <i  :class="menu.icon"></i>
        <span>{{menu.label}}</span>
      </template>

      <el-menu-item-group>
        <el-menu-item v-for="chmenu in menu.menuList" :index="'/'+chmenu.url" :key="chmenu.menuid">
          <i :class="chmenu.icon"></i>
          <span>{{chmenu.label}}</span>
        </el-menu-item>
      </el-menu-item-group>

    </el-submenu>
  </el-menu>

</template>
<script>
import { menu } from '../api/userMG'
import store from '@/vuex'
export default {
  name: 'leftnav',
  data() {
    return {
      collapsed: false,
      allmenu: [],
      avatar: ''
    }
  },
  // 创建完毕状态(里面是操作)
  created() {
    this.avatar = store.getters.avatar
    // 获取图形验证码
    let res = {
      success: true,
      data: [],
      msg: 'success'
    }

    data = this.search();
    // 监听
    this.$root.Bus.$on('toggle', value => {
      this.collapsed = !value
    })
  },
    methods: {
        async search() {//列表
            //发送查询请求
            let res = await menu();
            console.log(res)
            this.allmenu = res.data.menuList
        },
    }
}
</script>
<style>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 240px;
  min-height: 400px;
}
.el-menu-vertical-demo:not(.el-menu--collapse) {
  border: none;
  text-align: left;
}
.el-menu-item-group__title {
  padding: 0px;
}
.el-menu-bg {
  background-color: #1f2d3d !important;
}
.el-menu {
  border: none;
}
.logobox {
  height: 40px;
  line-height: 40px;
  color: #9d9d9d;
  font-size: 20px;
  text-align: center;
  padding: 20px 0px;
}
.logoimg {
  border-radius: 50%;
  border:2px solid white;
  height: 40px;
}

</style>
